<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use Illuminate\Http\Resources\Json\Resource;

class App extends Resource
{

    private $status = '1';
    private $message = 'success';
    public function toArray($request)
    {
        if(method_exists($this, $request->method) && $method = $request->method){
            return $this->$method();
        }
        $this->status = 'failed';
        $this->code = '404';
    }

    public function getItems(){
        return [
            'id'=>$this->id,
            'title'=>$this->title,
            'time'=>$this->time,
            'logo'=>env('APP_IMGURL').'/model/'.$this->logo,
        ];
    }

    public function getInfo(){
        $urls = explode('/',$this->url);
        return [
            'id'=>$this->id,
            'title'=>$this->title,
            'version'=>$this->version,
            'size'=>$this->size,
            'supportsystem'=>$this->supportsystem,
            'url'=>$this->url,
            'downurl'=>$this->downurl,
            'content'=>$this->content,
            'time'=>$this->time,
            'logo'=>env('APP_IMGURL').'/model/'.$this->logo,
        ];
    }

    public function with($request){
        return [
            'status' => $this->status,
            'message'   => $this->message,
        ];
    }
}
